<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      var obj = { value: 42 };
      function printValue() {
        console.log(this.value);
        return {
          aa: "看开点",
          bb: this.value,
        };
      }
      const dddd = printValue.call(obj); // 输出: 42
      console.log(dddd);

      var numbers = [5, 6, 2, 3, 7];
      var max = Math.max.apply(null, numbers); // 使用 apply 将数组作为参数传递
      console.log(max); // 输出: 7

      function greet(greeting) {
        console.log(greeting + ", " + this.name);
      }

      var user = { name: "Alice" };
      // var greetUser = greet.bind(user, "Hello"); // 创建并返回一个新函数

      // greetUser(); // 调用新函数，输出: Hello, Alice
      function mybind(obj) {
        let fn = this;
        return (val) => {
          fn.apply(obj,[val])
        };
        // return fn.apply(obj);
      }
      Function.prototype.mybind = mybind;
      var greetUser = greet.mybind(user, "Hello"); // 创建并返回一个新函数
      // console.dir(greetUser);

      greetUser('hello'); // 调用新函数，输出: Hello, Alice
    </script>
  </body>
</html>
